from multiprocessing import Process, Queue
import os, time, random
def write(q):
    print('Process to write: %s' % os.getpid())
    for value in ['A', 'B', 'C']:
        print('Put %s to queue...' % value)
        q.put(value)
        time.sleep(random.random())
def read(q):
    while True:
        value = q.get(True)
        print('进程%s开始Get %s from queue.' %(os.getpid(), value))
if __name__ == '__main__':
    q=Queue()
    pw=Process(target=write, args=(q,))
    pr=Process(target=read, args=(q,))
    pw.start()
    pr.start()
    pw.join()
    pr.terminate() # pw 进程里是死循环，无法等待其结束，只能强行终止